home *** CD-ROM | disk | FTP | other *** search
/ Aminet 16 / Aminet 16 (1996)(GTI - Schatztruhe)[!][Dec 1996].iso / Aminet / util / wb / finderv2.lha / Finder / Source / Finder_GUI.c < prev    next >
C/C++ Source or Header  |  1996-10-04  |  5KB  |  196 lines

  1. /*
  2.  *  Source machine generated by GadToolsBox V2.0b
  3.  *  which is (c) Copyright 1991-1993 Jaba Development
  4.  *
  5.  *  GUI Designed by : Chris Jones
  6.  */
  7.  
  8. #include "Finder_GUI.h"
  9.  
  10. struct Screen         *Scr = NULL;
  11. UBYTE                 *PubScreenName = NULL;
  12. APTR                   VisualInfo = NULL;
  13. struct Window         *FinderWnd = NULL;
  14. struct Gadget         *FinderGList = NULL;
  15. struct IntuiMessage    FinderMsg;
  16. UWORD                  FinderZoom[4];
  17. struct Gadget         *FinderGadgets[7];
  18. UWORD                  FinderLeft = 120;
  19. UWORD                  FinderTop = 104;
  20. UWORD                  FinderWidth = 397;
  21. UWORD                  FinderHeight = 300;
  22. UBYTE                 *FinderWdt = (UBYTE *)"Finder V2.06";
  23. struct TextAttr       *Font, Attr;
  24. UWORD                  FontX, FontY;
  25. UWORD                  OffX, OffY;
  26.  
  27. UWORD FinderGTypes[] = {
  28.     LISTVIEW_KIND,
  29.     STRING_KIND,
  30.     STRING_KIND,
  31.     BUTTON_KIND,
  32.     BUTTON_KIND,
  33.     BUTTON_KIND,
  34.     BUTTON_KIND
  35. };
  36.  
  37. struct NewGadget FinderNGad[] = {
  38.     5, 18, 386, 231, (UBYTE *)"F_iles found:", NULL, GD_filelister, PLACETEXT_ABOVE|NG_HIGHLABEL, NULL, NULL,
  39.     200, 252, 191, 19, (UBYTE *)"_Search Path", NULL, GD_path, PLACETEXT_LEFT|NG_HIGHLABEL, NULL, NULL,
  40.     200, 275, 191, 19, (UBYTE *)"_Pattern", NULL, GD_pattern, PLACETEXT_LEFT|NG_HIGHLABEL, NULL, NULL,
  41.     9, 252, 58, 19, (UBYTE *)"_Find", NULL, GD_find, PLACETEXT_IN, NULL, NULL,
  42.     68, 252, 58, 19, (UBYTE *)"_Quit", NULL, GD_quit, PLACETEXT_IN, NULL, NULL,
  43.     9, 275, 58, 19, (UBYTE *)"_Help", NULL, GD_help, PLACETEXT_IN, NULL, NULL,
  44.     68, 275, 58, 19, (UBYTE *)"_About", NULL, GD_about, PLACETEXT_IN, NULL, NULL
  45. };
  46.  
  47. ULONG FinderGTags[] = {
  48.     (GTLV_ShowSelected), NULL, (GTLV_ScrollWidth), 17, (GT_Underscore), '_', (TAG_DONE),
  49.     (GTST_MaxChars), 256, (GT_Underscore), '_', (TAG_DONE),
  50.     (GTST_MaxChars), 256, (GT_Underscore), '_', (TAG_DONE),
  51.     (GT_Underscore), '_', (TAG_DONE),
  52.     (GT_Underscore), '_', (TAG_DONE),
  53.     (GT_Underscore), '_', (TAG_DONE),
  54.     (GT_Underscore), '_', (TAG_DONE)
  55. };
  56.  
  57. static UWORD ComputeX( UWORD value )
  58. {
  59.     return(( UWORD )((( FontX * value ) + 3 ) / 6 ));
  60. }
  61.  
  62. static UWORD ComputeY( UWORD value )
  63. {
  64.     return(( UWORD )((( FontY * value ) + 5 ) / 11 ));
  65. }
  66.  
  67. static void ComputeFont( UWORD width, UWORD height )
  68. {
  69.     Font = &Attr;
  70.     Font->ta_Name = (STRPTR)Scr->RastPort.Font->tf_Message.mn_Node.ln_Name;
  71.     Font->ta_YSize = FontY = Scr->RastPort.Font->tf_YSize;
  72.     FontX = Scr->RastPort.Font->tf_XSize;
  73.  
  74.     OffX = Scr->WBorLeft;
  75.     OffY = Scr->RastPort.TxHeight + Scr->WBorTop + 1;
  76.  
  77.     if ( width && height ) {
  78.         if (( ComputeX( width ) + OffX + Scr->WBorRight ) > Scr->Width )
  79.             goto UseTopaz;
  80.         if (( ComputeY( height ) + OffY + Scr->WBorBottom ) > Scr->Height )
  81.             goto UseTopaz;
  82.     }
  83.     return;
  84.  
  85. UseTopaz:
  86.     Font->ta_Name = (STRPTR)"topaz.font";
  87.     FontX = FontY = Font->ta_YSize = 8;
  88. }
  89.  
  90. int SetupScreen( void )
  91. {
  92.     if ( ! ( Scr = LockPubScreen( PubScreenName )))
  93.         return( 1L );
  94.  
  95.     ComputeFont( 0, 0 );
  96.  
  97.     if ( ! ( VisualInfo = GetVisualInfo( Scr, TAG_DONE )))
  98.         return( 2L );
  99.  
  100.     return( 0L );
  101. }
  102.  
  103. void CloseDownScreen( void )
  104. {
  105.     if ( VisualInfo ) {
  106.         FreeVisualInfo( VisualInfo );
  107.         VisualInfo = NULL;
  108.     }
  109.  
  110.     if ( Scr        ) {
  111.         UnlockPubScreen( NULL, Scr );
  112.         Scr = NULL;
  113.     }
  114. }
  115.  
  116. int OpenFinderWindow( void )
  117. {
  118.     struct NewGadget    ng;
  119.     struct Gadget    *g;
  120.     UWORD        lc, tc;
  121.     UWORD        wleft = FinderLeft, wtop = FinderTop, ww, wh;
  122.  
  123.     ComputeFont( FinderWidth, FinderHeight );
  124.  
  125.     ww = ComputeX( FinderWidth );
  126.     wh = ComputeY( FinderHeight );
  127.  
  128.     if (( wleft + ww + OffX + Scr->WBorRight ) > Scr->Width ) wleft = Scr->Width - ww;
  129.     if (( wtop + wh + OffY + Scr->WBorBottom ) > Scr->Height ) wtop = Scr->Height - wh;
  130.  
  131.     if ( ! ( g = CreateContext( &FinderGList )))
  132.         return( 1L );
  133.  
  134.     for( lc = 0, tc = 0; lc < Finder_CNT; lc++ ) {
  135.  
  136.         CopyMem((char * )&FinderNGad[ lc ], (char * )&ng, (long)sizeof( struct NewGadget ));
  137.  
  138.         ng.ng_VisualInfo = VisualInfo;
  139.         ng.ng_TextAttr   = Font;
  140.         ng.ng_LeftEdge   = OffX + ComputeX( ng.ng_LeftEdge );
  141.         ng.ng_TopEdge    = OffY + ComputeY( ng.ng_TopEdge );
  142.         ng.ng_Width      = ComputeX( ng.ng_Width );
  143.         ng.ng_Height     = ComputeY( ng.ng_Height);
  144.  
  145.         FinderGadgets[ lc ] = g = CreateGadgetA((ULONG)FinderGTypes[ lc ], g, &ng, ( struct TagItem * )&FinderGTags[ tc ] );
  146.  
  147.         while( FinderGTags[ tc ] ) tc += 2;
  148.         tc++;
  149.  
  150.         if ( NOT g )
  151.             return( 2L );
  152.     }
  153.  
  154.         FinderZoom[0] = FinderZoom[1] = 0;
  155.     if ( FinderWdt )
  156.         FinderZoom[2] = TextLength( &Scr->RastPort, (UBYTE *)FinderWdt, strlen((char *)FinderWdt )) + 80;
  157.     else
  158.         FinderZoom[2]  = 80L;
  159.         FinderZoom[3] = Scr->WBorTop + Scr->RastPort.TxHeight + 1;
  160.  
  161.     if ( ! ( FinderWnd = OpenWindowTags( NULL,
  162.                 WA_Left,    wleft,
  163.                 WA_Top,        wtop,
  164.                 WA_Width,    ww + OffX + Scr->WBorRight,
  165.                 WA_Height,    wh + OffY + Scr->WBorBottom,
  166.                 WA_IDCMP,    LISTVIEWIDCMP|STRINGIDCMP|BUTTONIDCMP|IDCMP_CLOSEWINDOW|IDCMP_RAWKEY|IDCMP_VANILLAKEY|IDCMP_REFRESHWINDOW,
  167.                 WA_Flags,    WFLG_DRAGBAR|WFLG_DEPTHGADGET|WFLG_CLOSEGADGET|WFLG_SMART_REFRESH|WFLG_RMBTRAP,
  168.                 WA_Gadgets,    FinderGList,
  169.                 WA_Title,    FinderWdt,
  170.                 WA_ScreenTitle,    "Finder V2.06 by Chris Jones ©1996 Dynamic Software. All rights reserved.",
  171.                 WA_PubScreen,    Scr,
  172.                 WA_Zoom,    FinderZoom,
  173.                 WA_AutoAdjust,    TRUE,
  174.                 WA_PubScreenFallBack,    TRUE,
  175.                 TAG_DONE )))
  176.     return( 4L );
  177.  
  178.     GT_RefreshWindow( FinderWnd, NULL );
  179.  
  180.     return( 0L );
  181. }
  182.  
  183. void CloseFinderWindow( void )
  184. {
  185.     if ( FinderWnd        ) {
  186.         CloseWindow( FinderWnd );
  187.         FinderWnd = NULL;
  188.     }
  189.  
  190.     if ( FinderGList      ) {
  191.         FreeGadgets( FinderGList );
  192.         FinderGList = NULL;
  193.     }
  194. }
  195.  
  196.